// ͼתΪդλͼ
void Image1ToRasterCmd(int width, int height, bool * src, unsigned char * dst, int * dstlen)
{
    int x = (width + 7) / 8;
    int y = (height + 7) / 8 * 8;
    *dstlen = 8 + x * y;

    if (dst == NULL)
        return;

    memset(dst, 0, *dstlen);
    dst[0] = 0x1d;
    dst[1] = 0x76;
    dst[2] = 0x30;
    dst[3] = 0x00;
    dst[4] = (unsigned char)(x % 256);
    dst[5] = (unsigned char)(x / 256);
    dst[6] = (unsigned char)(y % 256);
    dst[7] = (unsigned char)(y / 256);

    unsigned char * bits = &dst[8];

    int idx = 0;
    unsigned char d = 0;

    for (int j = 0; j < height; ++j)
    {
        for (int i = 0; i < width; ++i)
        {
            int offset = PixOffset(width, i, j);
            if (i % 8 == 0)
            {
                d = (unsigned char)((src[offset] ? 0x01 : 0x00) << (7 - (i % 8)));
            }
            else
            {
                d |= (unsigned char)((src[offset] ? 0x01 : 0x00) << (7 - (i % 8)));
            }

            if ((i % 8 == 7) || (i == width - 1))
            {
                bits[idx++] = d;
            }
        }
    }
}
